package com.holyant.report.dto;

import cn.hutool.core.util.ObjectUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.List;
import java.util.Map;

@Data
@ApiModel("可视化报表2")
public class RptVisualReport2Dto {
    @ApiModelProperty("GMV")
    private TotalDto gmv;
    @ApiModelProperty("销量")
    private TotalDto qty;
    @ApiModelProperty("周转")
    private TotalDto turnover;
    @ApiModelProperty("销量数据TOP")
    private List<RptSaleDayQtyDto> qtyTop;
    @ApiModelProperty("周GMV数据")
    private List<WeekGmvDto> weekGmv;
    @ApiModelProperty("渠道数据销量")
    private List<ChannelTotalDataDto> channelQty;
    @ApiModelProperty("渠道数据GMV")
    private List<ChannelTotalDataDto> channelGmv;
    @ApiModelProperty("每周日均销量")
    private List<WeekDto> monthQty;
    @ApiModelProperty("每周日均GMV")
    private List<WeekDto> monthGmv;

    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @ApiModel("合计数据")
    public static class TotalDto {
        @ApiModelProperty("总数")
        private BigDecimal total;
        @ApiModelProperty("上月同期")
        private BigDecimal prevPeriod;
        @ApiModelProperty("增减率")
        private BigDecimal ratePercent;
    }

    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @ApiModel("周GMV数据")
    public static class WeekGmvDto implements Comparable<WeekGmvDto> {
        @ApiModelProperty("周")
        private Integer week;
        @ApiModelProperty("GMV")
        private BigDecimal gmv;
        @ApiModelProperty("销量")
        private BigDecimal salesQty;
        @Override
        public int compareTo(WeekGmvDto o) {
            return ObjectUtil.compare(week, o.week);
        }
    }

    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @ApiModel("渠道数据占比")
    public static class ChannelTotalDataDto {
        @ApiModelProperty("渠道")
        private String channel;
        private BigDecimal num;
        @ApiModelProperty("百分比")
        private BigDecimal percent;
        @ApiModelProperty("渠道详细")
        private List<ChannelDataDto> details;
    }

    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @ApiModel("渠道数据")
    public static class ChannelDataDto implements Comparable<ChannelDataDto> {
        private Long shopId;
        @ApiModelProperty("店铺名称")
        private String shopName;
        private Long customerId;
        @ApiModelProperty("客户名称")
        private String customerName;
        private BigDecimal num;
        @ApiModelProperty("百分比")
        private BigDecimal percent;

        @Override
        public int compareTo(ChannelDataDto o) {
            return ObjectUtil.compare(percent, o.percent);
        }
    }

    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @ApiModel("周日均数据")
    public static class WeekDto implements Comparable<WeekDto> {
        @ApiModelProperty("月份")
        private LocalDate month;
        @ApiModelProperty("是否合计")
        private boolean totalLine;
        private BigDecimal total;
        @ApiModelProperty("周")
        private Map<Integer, BigDecimal> weeks;

        @Override
        public int compareTo(WeekDto o) {
            int i = ObjectUtil.compare(totalLine, o.totalLine);
            return i == 0 ? ObjectUtil.compare(month, o.month) : i;
        }
    }

}
